package sg.edu.nus.iss.club;


import java.io.*;

public class ClubFileStore {
	
	private String fileName;
	
	public ClubFileStore(String fileName){
		this.fileName = fileName;
	}

	public void store(Club club) {
		FileOutputStream fos = null;
		try {
			File f = new File (fileName);
			fos = new FileOutputStream (f);
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(club);
			oos.writeInt(club.getMembers().size());
			oos.close();
			
		}catch(IOException ioe) {
			ioe.printStackTrace();
		}finally {
			try{
				fos.close();
			}catch(IOException ioe){}
			
		}
	}
	
	public void storeMembers(){
		
	}
	public void storeMember(Member m){
		
	}
	
	public void storeFacilitites(){
		
		
	}
	
	public Club retrieve() {
		Club result = null;
		FileInputStream fis = null;
		try {
			File f = new File (fileName);
			fis = new FileInputStream (f);
			ObjectInputStream ois = new ObjectInputStream(fis);
			result = (Club)ois.readObject();
			int index = ois.readInt();
			System.out.println(index);
			ois.close();
			
		}catch(Exception ex) {
			ex.printStackTrace();
		}finally {
			try{
				fis.close();
			}catch(IOException ioe){}
			
		}
		
		return result;
	}
}
